<template>
  <el-form-item :lable="label" v-bind="$attrs" v-on="$attrs" :class="`${prefixClass}`">
    <template #label>
      <div class="el-form-item__label" :class="[`${prefixClass}-label`]" :style="{ width: `${lableWidth}px` }">
        <span :class="[`${labelNameClass}`]">{{ label }}</span>
        <i
          v-if="deletable"
          class="font_family icon-tiaojianshanchu"
          :class="`${prefixClass}-label-delete`"
          @click="handleDelete"
        ></i>
      </div>
    </template>
    <slot></slot>
  </el-form-item>
</template>
<script lang="ts" setup>
import { defineProps, defineEmits } from 'vue'
const prefixClass = 'oy-form-item'

const props = defineProps({
  label: {
    type: String,
    default: '',
  },
  lableWidth: {
    type: [String, Number],
    // default: 100,
  },
  // label名称文案样式
  labelNameClass: {
    type: String,
    default: '',
  },
  // 是否可删除
  deletable: {
    type: Boolean,
    default: false,
  },
  name: {
    type: String,
    requried: true,
  },
})

const emit = defineEmits(['delete-item'])
const handleDelete = () => {
  emit('delete-item', props.name)
}
</script>
<style lang="less" scoped>
@prefix-cls: ~'oy-form-item';
.@{prefix-cls} {
  //   width: 100%;
  display: flex;
  text-align: left;
  &-label {
    display: flex;
    align-items: center;
    align-self: center;
    line-height: 18px;
    padding: 0;
    span {
      color: rgba(0, 0, 0, 0.85);
      font-family: MicrosoftYaHei;
      // font-weight: 600;
    }
    &-delete {
      margin-left: 2px;
      &:hover {
        cursor: pointer;
        color: var(--el-color-primary);
      }
    }
  }
  ::v-deep(.el-form-item) {
    margin-bottom: 18px !important;
    // .el-form-item__label {
    //   width: 100px;
    // }
    .el-form-item__content {
      width: 220px;
      max-width: 220px;
    }
  }
  ::v-deep(.el-input .el-input__wrapper) {
    width: 220px;
    max-width: 220px;
  }
}
</style>
